package com.edu.bhu.admin.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.edu.bhu.common.core.domain.entity.SysUser;
import com.edu.bhu.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.PreVaccinationMapper;
import com.edu.bhu.admin.domain.PreVaccination;
import com.edu.bhu.admin.service.IPreVaccinationService;
import com.edu.bhu.common.core.text.Convert;

/**
 * 疫苗接种Service业务层处理
 * 
 * @author yutianyang
 * @date 2022-04-23
 */
@Service
public class PreVaccinationServiceImpl implements IPreVaccinationService 
{
    @Autowired
    private PreVaccinationMapper preVaccinationMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询疫苗接种
     * 
     * @param detectionId 疫苗接种主键
     * @return 疫苗接种
     */
    @Override
    public PreVaccination selectPreVaccinationByDetectionId(Long detectionId)
    {
        return preVaccinationMapper.selectPreVaccinationByDetectionId(detectionId);
    }

    /**
     * 查询疫苗接种列表
     * 
     * @param preVaccination 疫苗接种
     * @return 疫苗接种
     */
    @Override
    public List<PreVaccination> selectPreVaccinationList(PreVaccination preVaccination)
    {
        List<PreVaccination> list = preVaccinationMapper.selectPreVaccinationList(preVaccination);
        list = list.stream().map(m ->{
            SysUser sysUser = sysUserMapper.selectUserById(m.getUserId());
            m.setSysUser(sysUser);
            return m;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 新增疫苗接种
     * 
     * @param preVaccination 疫苗接种
     * @return 结果
     */
    @Override
    public int insertPreVaccination(PreVaccination preVaccination)
    {
        return preVaccinationMapper.insertPreVaccination(preVaccination);
    }

    /**
     * 修改疫苗接种
     * 
     * @param preVaccination 疫苗接种
     * @return 结果
     */
    @Override
    public int updatePreVaccination(PreVaccination preVaccination)
    {
        return preVaccinationMapper.updatePreVaccination(preVaccination);
    }

    /**
     * 批量删除疫苗接种
     * 
     * @param detectionIds 需要删除的疫苗接种主键
     * @return 结果
     */
    @Override
    public int deletePreVaccinationByDetectionIds(String detectionIds)
    {
        return preVaccinationMapper.deletePreVaccinationByDetectionIds(Convert.toStrArray(detectionIds));
    }

    /**
     * 删除疫苗接种信息
     * 
     * @param detectionId 疫苗接种主键
     * @return 结果
     */
    @Override
    public int deletePreVaccinationByDetectionId(Long detectionId)
    {
        return preVaccinationMapper.deletePreVaccinationByDetectionId(detectionId);
    }
}
